%Figure S3
clear variables

load('Fig2_S2_S3_mobility.mat')

%% Figure S3 Panel A
%county level figures could take some time to render.

names = {county_shape.state};
indexHawaii_c = strcmp('Hawaii',names);
indexAlaska_c = strcmp('Alaska',names);
indexConus_c = 1:numel(county_shape);
indexConus_c(indexHawaii_c|indexAlaska_c) = []; 

states = shaperead('usastatelo', 'UseGeoCoords', true);
names = {states.Name};
indexHawaii = strcmp('Hawaii',names);
indexAlaska = strcmp('Alaska',names);
indexConus = 1:numel(states);
indexConus(indexHawaii|indexAlaska) = [];

% county map
figure
ax = usamap('all');
set(ax, 'Visible', 'off')
surfaceColors = makesymbolspec('Polygon', {'a', ...
    [log10(min(county_fit(:,1))) log10(county_fit(1799,1))], 'FaceColor', flipud(hot(12)) });

% Display the three regions.
geoshow(ax(1), county_shape(indexConus_c),  'DisplayType','polygon','SymbolSpec', surfaceColors,...
    'DefaultFaceColor','#C0C0C0','DefaultEdgeColor','none')
% geoshow(ax(2), county_shape(indexAlaska_c), 'DisplayType','polygon','SymbolSpec', surfaceColors,...
%     'DefaultFaceColor','#C0C0C0','DefaultEdgeColor','none')
geoshow(ax(3), county_shape(indexHawaii_c), 'DisplayType','polygon','SymbolSpec', surfaceColors,...
    'DefaultFaceColor','#C0C0C0','DefaultEdgeColor','none')

%plot state lines
geoshow(ax(1), states(indexConus),'DisplayType','polygon','DefaultFaceColor','none')
% geoshow(ax(2), states(indexAlaska),'DisplayType','polygon','DefaultFaceColor','none')
geoshow(ax(3), states(indexHawaii),'DisplayType','polygon','DefaultFaceColor','none')

% Hide the frame.
caxis([log10(min(county_fit(:,1))) log10(county_fit(1799,1))])
colormap(flipud(hot(12)))
colorbar

for k = 1:3
    setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
      'ParallelLabel', 'off', 'MeridianLabel', 'off')
end

%% Figure S3 Panel B
%county level figures could take some time to render.

names = {county_shape.state};
indexHawaii_c = strcmp('Hawaii',names);
indexAlaska_c = strcmp('Alaska',names);
indexConus_c = 1:numel(county_shape);
indexConus_c(indexHawaii_c|indexAlaska_c) = []; 

% county map
figure
ax = usamap('all');
set(ax, 'Visible', 'off')

surfaceColors = makesymbolspec('Polygon', {'b', ...
    [0 max(county_fit(:,2))], 'FaceColor', flipud(hot(12)) });

% Display the three regions.
geoshow(ax(1), county_shape(indexConus_c),  'DisplayType','polygon','SymbolSpec', surfaceColors,...
    'DefaultFaceColor','#C0C0C0','DefaultEdgeColor','none')
% geoshow(ax(2), county_shape(indexAlaska_c), 'DisplayType','polygon','SymbolSpec', surfaceColors,...
%     'DefaultFaceColor','#C0C0C0','DefaultEdgeColor','none')
geoshow(ax(3), county_shape(indexHawaii_c), 'DisplayType','polygon','SymbolSpec', surfaceColors,...
    'DefaultFaceColor','#C0C0C0','DefaultEdgeColor','none')

%plot state lines
geoshow(ax(1), states(indexConus),'DisplayType','polygon','DefaultFaceColor','none')
% geoshow(ax(2), states(indexAlaska),'DisplayType','polygon','DefaultFaceColor','none')
geoshow(ax(3), states(indexHawaii),'DisplayType','polygon','DefaultFaceColor','none')

% Hide the frame.
caxis([0 max(county_fit(:,2))])
colormap(flipud(hot(12)))
colorbar

for k = 1:3
    setm(ax(k), 'Frame', 'off', 'Grid', 'off',...
      'ParallelLabel', 'off', 'MeridianLabel', 'off')
end
%% Figure S3 Panel C
figure
scatter(log10(us_state_popdens),log10(a_new))
xlabel('Log of population density')
ylabel('Log of a')
text(2.5,2,'R{^2}=0.93','FontSize',14)

%% Figure S3 Panel D
figure
scatter(log10(us_state_popdens),b_new)
xlabel('Log of population density')
ylabel('b')
text(2.5,4.5,'R{^2}=0.21','FontSize',14)